package org.tech4j.common.core.sign.extractor;

import jakarta.servlet.http.HttpServletRequest;
import org.tech4j.common.core.constant.Constants;
import org.tech4j.common.core.sign.api.SignParameters;

import java.net.URI;

/**
 * @program: tech4j-common
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/2 19:44
 **/
public class VersionOneExtractor implements SignParameterExtractor {
    public static final String VERSION_1 = "1.0.0";

    @Override
    public SignParameters extract(HttpServletRequest request) {
        String appKey = request.getHeader(Constants.APP_KEY);
        String signature = request.getHeader(Constants.SIGN);
        String timestamp = request.getHeader(Constants.TIMESTAMP);
        String uri = request.getRequestURI();
        return new SignParameters(VERSION_1, appKey, timestamp, signature, URI.create(uri));
    }

    @Override
    public SignParameters extract(HttpServletRequest request, String paramType, String paramKey) {
        return extract(request);
    }
}
